<?php

namespace App\Http\Requests\base;

use App\Http\ValidateResult;
use Illuminate\Support\Facades\Validator;

trait ExchangeRateRequest
{
    public static function add_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'currency_id' => 'required',
            'exchange_currency_id' => 'required',
            'rate' => 'required',
            'invalid_time' => 'required',
        ], [
            'currency_id.required' => '请选择原币种',
            'exchange_currency_id.required' => '请选择换算币种',
            'rate.required' => '请填写汇率',
            'invalid_time.required' => '请选择生效时间',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

}
